package com.mapapp.flutter_mapapp.persenter;

import android.content.Context;

import com.mapapp.flutter_mapapp.bean.HistoryDetail;
import com.mapapp.flutter_mapapp.http.ActivityLifeCycleEvent;
import com.mapapp.flutter_mapapp.http.Api;
import com.mapapp.flutter_mapapp.http.HttpUtil;
import com.mapapp.flutter_mapapp.http.ProgressSubscriber;
import com.mapapp.flutter_mapapp.util.ToastUtils;
import com.mapapp.flutter_mapapp.view.HistoryDetailViewInterface;

import rx.subjects.PublishSubject;

public class HistoryDetailPresenter {
    private Context mContext;
    private HistoryDetailViewInterface mView;
    private PublishSubject<ActivityLifeCycleEvent> lifecycleSubject;

    public HistoryDetailPresenter(HistoryDetailViewInterface view, Context context, PublishSubject<ActivityLifeCycleEvent> lifecycleSubject) {
        this.mView = view;
        this.mContext = context;
        this.lifecycleSubject = lifecycleSubject;
    }

    public void getHistory(String opId) {
        HttpUtil.getInstance().toSubscribe(Api.getApiService().getOperationHistoryDetail(opId),
                new ProgressSubscriber<HistoryDetail>(mContext, false) {
                    @Override
                    protected void _onNext(HistoryDetail historyDetail) {
                        mView.showHistoryDetail(historyDetail);
                    }

                    @Override
                    protected void _onError(String message) {
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);
    }
}
